// 这里要记得循环的条件是 aL < arr1.length  && bL < arr2.length ，不是取2个数组长度的最小值
const merge = function (arr1, arr2) {
  let res = [];
  let aL = 0;
  let bL = 0;
  while (aL < arr1.length && bL < arr2.length) {
    if (arr1[aL] < arr2[bL]) {
      res.push(arr1[aL]);
      aL++;
    } else if (arr1[aL] >= arr2[bL]) {
      res.push(arr2[bL]);
      bL++;
    }
  }

  while (aL < arr1.length) {
    res.push(arr1[aL++]);
  }

  while (bL < arr2.length) {
    res.push(arr2[bL++]);
  }

  return res;
};

console.log(merge([1, 2, 3, 4, 10], [5, 6, 7, 8]));
